package com.abc.robot01.activity.compose

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ListItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedCard
import androidx.compose.material3.Slider
import androidx.compose.material3.Surface
import androidx.compose.material3.SwipeToDismissBox
import androidx.compose.material3.SwipeToDismissBoxValue
import androidx.compose.material3.Text
import androidx.compose.material3.rememberSwipeToDismissBoxState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.navigation.ui.AppBarConfiguration
import com.abc.robot01.activity.px
import com.abc.robot01.databinding.ActivityMainBinding
import kotlinx.coroutines.launch


//https://github.com/android/compose-samples
//https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/TabSamples.kt
//
//https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/SwipeToDismissSamples.kt

// https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/material3/material3/samples/src/main/java/androidx/compose/material3/samples/DatePickerSamples.kt

class SwipeToDismissBoxSamples : ComponentActivity() {

    @OptIn(ExperimentalMaterial3Api::class)
    @Composable
    fun SwipeToDismissWithRedBackground() {
        val scope = rememberCoroutineScope()
        val dismissBoxState = rememberSwipeToDismissBoxState(positionalThreshold={500f})
        SwipeToDismissBox(
            state = dismissBoxState ,
            backgroundContent = {
                Box(
                    modifier = Modifier
                        .fillMaxSize(),
//                        .background(Color.Red),
                    contentAlignment = Alignment.CenterEnd
                ) {
                    Text("Delete", color = Color.Red)
                }
            },
            content = {
                Box(
                    modifier = Modifier
                        .fillMaxWidth()
                        .padding(16.dp)
                        .background(Color.LightGray)
                ) {
                    Text("Swipe to delete")
                }
            }
        )
        LaunchedEffect(dismissBoxState.currentValue) {
            if(dismissBoxState.currentValue == SwipeToDismissBoxValue.EndToStart){
                scope.launch {
                    Log.e(TAG,"EndToStart");
                }
            }
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.e("FirstFragment","MainActivity  onCreate");
        setContent {
            MaterialTheme {
                Surface() {
                    Column( modifier = Modifier
                        .fillMaxSize()
                        .verticalScroll(rememberScrollState())
                        .padding(8.dp),
                        verticalArrangement = Arrangement.spacedBy(8.dp)) {
                        SwipeToDismissWithRedBackground()
                    }
                }
            }
        }
        }

    companion object{
     val  TAG="SwipeToDismissBoxSamples"
    }
}

